<?php
include 'inc/header.php';

$x = 5; // 全局变量

function myTest()
{
    $y = 10; // 局部变量
    comment("Test variables inside the function:");
    clog("Variable x is: $x"); // 访问不到全局变量
    newline();
    clog("Variable y is: $y");
}


function printGlobalVar()
{
    global $x;
    clog("global var \$x is $x");
}


title('变量和作用域');
myTest();
printGlobalVar();

comment("Test variables outside the function:");
clog("Variable x is: $x");
newline();
clog("Variable y is: $y"); // 访问不到局部变量


comment('静态变量，函数执行完后不会被销毁');
function countUp()
{
    static $x = 0;
    $x++;
    clog("\$x is: $x");
}

countUp();
countUp();
countUp();
countUp();

include 'inc/footer.php';
